home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / swtools / libdwarf / pro_forms.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  20.0 KB  |  755 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <limits.h>
  4. #include "pro_incl.h"
  5. #include "pro_expr.h"
  6.  
  7.     /* Indicates no relocation needed. */
  8. #define NO_ELF_SYM_INDEX    0
  9.  
  10. #define GET_DISP(dbg,val) (IS_64BIT(dbg) ? (char *)&val : ((char *)&val + 4))
  11.  
  12. /* adds an attribute to a die */
  13. extern void _dwarf_pro_add_at_to_die (Dwarf_P_Die die, Dwarf_P_Attribute attr);
  14.  
  15. /*
  16.     This function adds an attribute whose value is
  17.     a target address to the given die.  The attribute
  18.     is given the name provided by attr.  The address
  19.     is given in pc_value.
  20. */
  21. Dwarf_P_Attribute 
  22. dwarf_add_AT_targ_address (
  23.     Dwarf_P_Debug    dbg,
  24.     Dwarf_P_Die     ownerdie,
  25.     Dwarf_Half        attr,
  26.     Dwarf_Unsigned    pc_value,
  27.     Dwarf_Signed    sym_index,
  28.     Dwarf_Error     *error
  29. )
  30. {
  31.     Dwarf_P_Attribute     new_attr;
  32.  
  33.     if (dbg == NULL) {
  34.         _dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
  35.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  36.     }
  37.  
  38.     if (ownerdie == NULL) {
  39.         _dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
  40.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  41.     }
  42.  
  43.     if (attr != DW_AT_low_pc && attr != DW_AT_high_pc &&
  44.     attr != DW_AT_MIPS_loop_begin && attr != DW_AT_MIPS_tail_loop_begin &&
  45.     attr != DW_AT_MIPS_epilog_begin) {
  46.         _dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD);
  47.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  48.     }
  49.  
  50.     new_attr = (Dwarf_P_Attribute)
  51.         _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s));
  52.     if (new_attr == NULL) {
  53.         _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
  54.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  55.     }
  56.  
  57.     new_attr->ar_attribute = attr;
  58.     new_attr->ar_attribute_form = DW_FORM_addr;
  59.     new_attr->ar_nbytes = SIZEOF_UWORD(dbg);
  60.     new_attr->ar_rel_symidx = sym_index;
  61.     if (sym_index != NO_ELF_SYM_INDEX)
  62.         new_attr->ar_rel_type = IS_64BIT(dbg) ? R_MIPS_64 : R_MIPS_32;
  63.     else 
  64.     new_attr->ar_rel_type = R_MIPS_NONE;
  65.  
  66.     new_attr->ar_data = (char *)
  67.         _dwarf_p_get_alloc(dbg, SIZEOF_UWORD(dbg));
  68.     if (new_attr->ar_data == NULL) {
  69.         _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
  70.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  71.     }
  72.     memcpy(new_attr->ar_data, GET_DISP(dbg, pc_value), SIZEOF_UWORD(dbg));
  73.  
  74.     /* add attribute to the die */
  75.     _dwarf_pro_add_at_to_die(ownerdie, new_attr);
  76.     return new_attr;
  77. }
  78.  
  79.  
  80. /*
  81.     This function adds attributes whose value
  82.     is an unsigned constant.  It determines the 
  83.     size of the value field from the value of 
  84.     the constant.
  85. */
  86. Dwarf_P_Attribute 
  87. dwarf_add_AT_unsigned_const (
  88.     Dwarf_P_Debug    dbg,
  89.     Dwarf_P_Die     ownerdie,
  90.     Dwarf_Half        attr,
  91.     Dwarf_Unsigned    value,
  92.     Dwarf_Error     *error
  93. )
  94. {
  95.     Dwarf_P_Attribute     new_attr;
  96.     Dwarf_Half        attr_form;
  97.     Dwarf_Small        size;
  98.  
  99.     if (dbg == NULL) {
  100.         _dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
  101.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  102.     }
  103.  
  104.     if (ownerdie == NULL) {
  105.         _dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
  106.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  107.     }
  108.  
  109.     switch (attr) {
  110.         case DW_AT_ordering :
  111.         case DW_AT_byte_size :
  112.         case DW_AT_bit_offset :
  113.         case DW_AT_bit_size :
  114.     case DW_AT_inline :
  115.         case DW_AT_language :
  116.         case DW_AT_visibility: 
  117.         case DW_AT_virtuality :
  118.     case DW_AT_accessibility :
  119.     case DW_AT_address_class :
  120.     case DW_AT_calling_convention :
  121.     case DW_AT_encoding :
  122.     case DW_AT_identifier_case :
  123.     case DW_AT_MIPS_loop_unroll_factor :
  124.     case DW_AT_MIPS_software_pipeline_depth :
  125.             break;
  126.  
  127.     case DW_AT_decl_column :
  128.     case DW_AT_decl_file :
  129.     case DW_AT_decl_line :
  130.     case DW_AT_const_value :
  131.     case DW_AT_start_scope :
  132.     case DW_AT_stride_size :
  133.     case DW_AT_count :
  134.         break;
  135.  
  136.         default : {
  137.             _dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD);
  138.             return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  139.         }
  140.     }
  141.  
  142.     /* 
  143.         Compute the number of bytes 
  144.         needed to hold constant.
  145.     */
  146.     if (value <= UCHAR_MAX) {attr_form = DW_FORM_data1; size = 1;}
  147.     else if (value <= USHRT_MAX) {attr_form = DW_FORM_data2; size = 2;}
  148.     else if (value <= UINT_MAX) {attr_form = DW_FORM_data4; size = 4;}
  149.     else {attr_form = DW_FORM_data8; size = 8;}
  150.  
  151.     new_attr = (Dwarf_P_Attribute)
  152.         _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s));
  153.     if (new_attr == NULL) {
  154.         _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
  155.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  156.     }
  157.  
  158.     new_attr->ar_attribute = attr;
  159.     new_attr->ar_attribute_form = attr_form;
  160.     new_attr->ar_rel_type = R_MIPS_NONE;
  161.     new_attr->ar_nbytes = size;
  162.  
  163.     new_attr->ar_data = (char *)
  164.         _dwarf_p_get_alloc(dbg, size);
  165.     if (new_attr->ar_data == NULL) {
  166.         _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
  167.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  168.     }
  169.     memcpy(new_attr->ar_data, (char *)&value+sizeof(Dwarf_Unsigned)-size, size);
  170.  
  171.     /* add attribute to the die */
  172.     _dwarf_pro_add_at_to_die(ownerdie, new_attr);
  173.     return new_attr;
  174. }
  175.  
  176.  
  177. /*
  178.     This function adds attributes whose value
  179.     is an signed constant.  It determines the 
  180.     size of the value field from the value of 
  181.     the constant.
  182. */
  183. Dwarf_P_Attribute 
  184. dwarf_add_AT_signed_const (
  185.     Dwarf_P_Debug        dbg,
  186.     Dwarf_P_Die         ownerdie,
  187.     Dwarf_Half        attr,
  188.     Dwarf_Signed    value,
  189.     Dwarf_Error     *error
  190. )
  191. {
  192.     Dwarf_P_Attribute     new_attr;
  193.     Dwarf_Half        attr_form;
  194.     Dwarf_Small        size;
  195.  
  196.     if (dbg == NULL) {
  197.         _dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
  198.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  199.     }
  200.  
  201.     if (ownerdie == NULL) {
  202.         _dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
  203.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  204.     }
  205.  
  206.     switch (attr) {
  207.     case DW_AT_upper_bound :
  208.     case DW_AT_lower_bound :
  209.         break;
  210.  
  211.         default : {
  212.             _dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD);
  213.             return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  214.         }
  215.     }
  216.  
  217.     /* 
  218.         Compute the number of bytes 
  219.         needed to hold constant.
  220.     */
  221.     if (value >= SCHAR_MIN && value <= SCHAR_MAX) 
  222.     {attr_form = DW_FORM_data1; size = 1;}
  223.     else if (value >= SHRT_MIN && value <= SHRT_MAX) 
  224.     {attr_form = DW_FORM_data2; size = 2;}
  225.     else if (value >= INT_MIN && value <= INT_MAX) 
  226.     {attr_form = DW_FORM_data4; size = 4;}
  227.     else 
  228.     {attr_form = DW_FORM_data8; size = 8;}
  229.  
  230.     new_attr = (Dwarf_P_Attribute)
  231.         _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s));
  232.     if (new_attr == NULL) {
  233.         _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
  234.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  235.     }
  236.  
  237.     new_attr->ar_attribute = attr;
  238.     new_attr->ar_attribute_form = attr_form;
  239.     new_attr->ar_rel_type = R_MIPS_NONE;
  240.     new_attr->ar_nbytes = size;
  241.  
  242.     new_attr->ar_data = (char *)
  243.         _dwarf_p_get_alloc(dbg, size);
  244.     if (new_attr->ar_data == NULL) {
  245.         _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
  246.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  247.     }
  248.     memcpy(new_attr->ar_data, (char *)&value+sizeof(Dwarf_Signed)-size, size);
  249.  
  250.     /* add attribute to the die */
  251.     _dwarf_pro_add_at_to_die(ownerdie, new_attr);
  252.     return new_attr;
  253. }
  254.  
  255.  
  256. /*
  257.     This function adds attributes whose value
  258.     is a location expression.
  259. */
  260. Dwarf_P_Attribute 
  261. dwarf_add_AT_location_expr (
  262.     Dwarf_P_Debug    dbg,
  263.     Dwarf_P_Die     ownerdie,
  264.     Dwarf_Half        attr,
  265.     Dwarf_P_Expr    loc_expr,
  266.     Dwarf_Error     *error
  267. )
  268. {
  269.     Dwarf_P_Attribute     new_attr;
  270.     Dwarf_Half        attr_form;
  271.     char        *len_str;
  272.     int            len_size;
  273.     int            block_size;
  274.     char        *block_dest_ptr;
  275.  
  276.     if (dbg == NULL) {
  277.         _dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
  278.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  279.     }
  280.  
  281.     if (ownerdie == NULL) {
  282.         _dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
  283.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  284.     }
  285.  
  286.     if (loc_expr == NULL) {
  287.     _dwarf_p_error(dbg, error, DW_DLE_EXPR_NULL);
  288.     return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  289.     }
  290.  
  291.     if (loc_expr->ex_dbg != dbg) {
  292.     _dwarf_p_error(dbg, error, DW_DLE_LOC_EXPR_BAD);
  293.     return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  294.     }
  295.     block_size = loc_expr->ex_next_byte_offset;
  296.  
  297.     switch (attr) {
  298.     case DW_AT_location :
  299.     case DW_AT_string_length :
  300.     case DW_AT_const_value :
  301.     case DW_AT_use_location :
  302.     case DW_AT_return_addr :
  303.     case DW_AT_data_member_location :
  304.     case DW_AT_frame_base :
  305.     case DW_AT_static_link :
  306.     case DW_AT_vtable_elem_location :
  307.         break;
  308.  
  309.         default : {
  310.             _dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD);
  311.             return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  312.         }
  313.     }
  314.  
  315.     /* 
  316.         Compute the number of bytes 
  317.         needed to hold constant.
  318.     */
  319.     if (block_size <= UCHAR_MAX) {
  320.     attr_form = DW_FORM_block1; 
  321.     len_str = (char *)&block_size + sizeof(block_size) - 1;
  322.     len_size = 1;
  323.     }
  324.     else if (block_size <= USHRT_MAX) {
  325.     attr_form = DW_FORM_block2; 
  326.     len_str = (char *)&block_size + sizeof(block_size) - 2;
  327.     len_size = 2;
  328.     }
  329.     else if (block_size <= UINT_MAX) {
  330.     attr_form = DW_FORM_block4; 
  331.     len_str = (char *)&block_size + sizeof(block_size) - 4;
  332.     len_size = 4;
  333.     }
  334.     else {
  335.     attr_form = DW_FORM_block; 
  336.     len_str = _dwarf_pro_encode_leb128(block_size, &len_size);
  337.     if (len_str == NULL) {
  338.         _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
  339.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  340.     }
  341.     }
  342.  
  343.     new_attr = (Dwarf_P_Attribute)
  344.         _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s));
  345.     if (new_attr == NULL) {
  346.         _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
  347.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  348.     }
  349.  
  350.     new_attr->ar_attribute = attr;
  351.     new_attr->ar_attribute_form = attr_form;
  352.  
  353.     if (loc_expr->ex_reloc_sym_index != NO_ELF_SYM_INDEX)
  354.     new_attr->ar_rel_type = IS_64BIT(dbg) ? R_MIPS_64 : R_MIPS_32;
  355.     else
  356.         new_attr->ar_rel_type = R_MIPS_NONE;
  357.     new_attr->ar_rel_symidx = loc_expr->ex_reloc_sym_index;
  358.     new_attr->ar_rel_offset = loc_expr->ex_reloc_offset + len_size;
  359.  
  360.     new_attr->ar_nbytes = block_size + len_size;
  361.  
  362.     new_attr->ar_data = block_dest_ptr = 
  363.     (char *)_dwarf_p_get_alloc(dbg, block_size + len_size);
  364.     if (new_attr->ar_data == NULL) {
  365.         _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
  366.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  367.     }
  368.  
  369.     memcpy(block_dest_ptr, len_str, len_size);
  370.     block_dest_ptr += len_size;
  371.     memcpy(block_dest_ptr, &(loc_expr->ex_byte_stream[0]), block_size);
  372.  
  373.     /* add attribute to the die */
  374.     _dwarf_pro_add_at_to_die(ownerdie, new_attr);
  375.     return new_attr;
  376. }
  377.  
  378.  
  379. /*
  380.     This function adds attributes of reference class.
  381.     The offset field is 4 bytes for 32-bit objects,
  382.     and 8-bytes for 64-bit objects.  Otherdie is the
  383.     that is referenced by ownerdie.
  384.  
  385.     For reference attributes, the ar_data and ar_nbytes
  386.     are not needed.  Instead, the ar_ref_die points to
  387.     the other die, and its di_offset value is used as
  388.     the reference value.
  389. */
  390. Dwarf_P_Attribute 
  391. dwarf_add_AT_reference (
  392.     Dwarf_P_Debug    dbg,
  393.     Dwarf_P_Die     ownerdie,
  394.     Dwarf_Half        attr,
  395.     Dwarf_P_Die        otherdie,
  396.     Dwarf_Error     *error
  397. )
  398. {
  399.     Dwarf_P_Attribute     new_attr;
  400.  
  401.     if (dbg == NULL) {
  402.         _dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
  403.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  404.     }
  405.  
  406.     if (ownerdie == NULL) {
  407.         _dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
  408.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  409.     }
  410.  
  411.     if (otherdie == NULL) {
  412.     _dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
  413.     return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  414.     }
  415.  
  416.     switch (attr) {
  417.         case DW_AT_specification :
  418.         case DW_AT_discr :
  419.         case DW_AT_common_reference :
  420.         case DW_AT_import :
  421.         case DW_AT_containing_type :
  422.         case DW_AT_default_value: 
  423.         case DW_AT_abstract_origin :
  424.         case DW_AT_friend :
  425.         case DW_AT_priority :
  426.         case DW_AT_type : 
  427.     case DW_AT_lower_bound :
  428.     case DW_AT_upper_bound :
  429.     case DW_AT_count :
  430.     case DW_AT_sibling:
  431.             break;
  432.  
  433.         default : {
  434.             _dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD);
  435.             return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  436.         }
  437.     }
  438.  
  439.     new_attr = (Dwarf_P_Attribute)
  440.         _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s));
  441.     if (new_attr == NULL) {
  442.         _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
  443.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  444.     }
  445.  
  446.     new_attr->ar_attribute = attr;
  447.     new_attr->ar_attribute_form = 
  448.         IS_64BIT(dbg) ? DW_FORM_ref8 : DW_FORM_ref4;
  449.     new_attr->ar_nbytes = IS_64BIT(dbg) ? 8 : 4;
  450.     new_attr->ar_ref_die = otherdie;
  451.     new_attr->ar_rel_type = R_MIPS_NONE;
  452.  
  453.     /* add attribute to the die */
  454.     _dwarf_pro_add_at_to_die(ownerdie, new_attr);
  455.     return new_attr;
  456. }
  457.  
  458.  
  459. /*
  460.     This function adds attributes of the flag class.
  461. */
  462. Dwarf_P_Attribute 
  463. dwarf_add_AT_flag (
  464.     Dwarf_P_Debug        dbg,
  465.     Dwarf_P_Die         ownerdie,
  466.     Dwarf_Half        attr,
  467.     Dwarf_Small        flag,
  468.     Dwarf_Error     *error
  469. )
  470. {
  471.     Dwarf_P_Attribute     new_attr;
  472.  
  473.     if (dbg == NULL) {
  474.         _dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
  475.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  476.     }
  477.  
  478.     if (ownerdie == NULL) {
  479.         _dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
  480.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  481.     }
  482.  
  483.     switch (attr) {
  484.         case DW_AT_is_optional :
  485.         case DW_AT_artificial :
  486.         case DW_AT_declaration :
  487.         case DW_AT_external :
  488.     case DW_AT_prototyped :
  489.     case DW_AT_variable_parameter :
  490.             break;
  491.  
  492.         default : {
  493.             _dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD);
  494.             return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  495.         }
  496.     }
  497.  
  498.     new_attr = (Dwarf_P_Attribute)
  499.         _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s));
  500.     if (new_attr == NULL) {
  501.         _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
  502.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  503.     }
  504.  
  505.     new_attr->ar_attribute = attr;
  506.     new_attr->ar_attribute_form = DW_FORM_flag;
  507.     new_attr->ar_nbytes = 1;
  508.     new_attr->ar_rel_type = R_MIPS_NONE;
  509.  
  510.     new_attr->ar_data = (char *)
  511.         _dwarf_p_get_alloc(dbg, 1);
  512.     if (new_attr->ar_data == NULL) {
  513.         _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
  514.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  515.     }
  516.     memcpy(new_attr->ar_data, &flag, 1);
  517.  
  518.     /* add attribute to the die */
  519.     _dwarf_pro_add_at_to_die(ownerdie, new_attr);
  520.     return new_attr;
  521. }
  522.  
  523.  
  524. /*
  525.     This function adds values of attributes
  526.     belonging to the string class.
  527. */
  528. Dwarf_P_Attribute 
  529. dwarf_add_AT_string (
  530.     Dwarf_P_Debug    dbg,
  531.     Dwarf_P_Die     ownerdie,
  532.     Dwarf_Half        attr,
  533.     char         *string,
  534.     Dwarf_Error     *error
  535. )
  536. {
  537.     Dwarf_P_Attribute     new_attr;
  538.  
  539.     if (dbg == NULL) {
  540.     _dwarf_p_error(NULL, error, DW_DLE_DBG_NULL);
  541.     return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  542.     }
  543.  
  544.     if (ownerdie == NULL) {
  545.     _dwarf_p_error(dbg, error, DW_DLE_DIE_NULL);
  546.     return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  547.     }
  548.  
  549.     new_attr = (Dwarf_P_Attribute)
  550.         _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s));
  551.     if (new_attr == NULL) {
  552.         _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
  553.     return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  554.     }
  555.  
  556.     switch (attr) {
  557.     case DW_AT_name :
  558.     case DW_AT_comp_dir :
  559.     case DW_AT_const_value :
  560.     case DW_AT_producer :
  561.     case DW_AT_MIPS_linkage_name :
  562.         break;
  563.  
  564.     default : {
  565.         _dwarf_p_error(dbg, error, DW_DLE_INPUT_ATTR_BAD);
  566.         return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  567.     }
  568.     }
  569.  
  570.     new_attr->ar_attribute = attr;
  571.     new_attr->ar_attribute_form = DW_FORM_string;
  572.     new_attr->ar_nbytes = strlen(string) + 1;
  573.     new_attr->ar_next = NULL;
  574.  
  575.     new_attr->ar_data = 
  576.     (char *)_dwarf_p_get_alloc(NULL, strlen(string)+1);
  577.     if (new_attr->ar_data == NULL) {
  578.         _dwarf_p_error(dbg, error, DW_DLE_ALLOC_FAIL);
  579.     return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  580.     }
  581.  
  582.     strcpy(new_attr->ar_data, string);
  583.     new_attr->ar_rel_type = R_MIPS_NONE;
  584.  
  585.     /* add attribute to the die */
  586.     _dwarf_pro_add_at_to_die(ownerdie, new_attr);
  587.     return new_attr;
  588. }
  589.  
  590.  
  591. Dwarf_P_Attribute 
  592. dwarf_add_AT_const_value_string (
  593.     Dwarf_P_Die         ownerdie,
  594.     char         *string_value,
  595.     Dwarf_Error     *error
  596. )
  597. {
  598.     Dwarf_P_Attribute     new_attr;
  599.  
  600.     if (ownerdie == NULL) {
  601.     _dwarf_p_error(NULL, error, DW_DLE_DIE_NULL);
  602.     return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  603.     }
  604.  
  605.     new_attr = (Dwarf_P_Attribute)
  606.         _dwarf_p_get_alloc(NULL, sizeof(struct Dwarf_P_Attribute_s));
  607.     if (new_attr == NULL) {
  608.         _dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
  609.     return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  610.     }
  611.  
  612.     new_attr->ar_attribute = DW_AT_const_value;
  613.     new_attr->ar_attribute_form = DW_FORM_string;
  614.     new_attr->ar_nbytes = strlen(string_value) + 1;
  615.     new_attr->ar_next = NULL;
  616.  
  617.     new_attr->ar_data = 
  618.     (char *)_dwarf_p_get_alloc(NULL, strlen(string_value)+1);
  619.     if (new_attr->ar_data == NULL) {
  620.         _dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
  621.     return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  622.     }
  623.  
  624.     strcpy(new_attr->ar_data, string_value);
  625.     new_attr->ar_rel_type = R_MIPS_NONE;
  626.  
  627.     /* add attribute to the die */
  628.     _dwarf_pro_add_at_to_die(ownerdie, new_attr);
  629.     return new_attr;
  630. }
  631.  
  632.  
  633. Dwarf_P_Attribute 
  634. dwarf_add_AT_producer (
  635.     Dwarf_P_Die         ownerdie,
  636.     char         *producer_string,
  637.     Dwarf_Error     *error
  638. )
  639. {
  640.     Dwarf_P_Attribute     new_attr;
  641.  
  642.     if (ownerdie == NULL) {
  643.         _dwarf_p_error(NULL, error, DW_DLE_DIE_NULL);
  644.     return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  645.     }
  646.  
  647.     new_attr = (Dwarf_P_Attribute)
  648.         _dwarf_p_get_alloc(NULL, sizeof(struct Dwarf_P_Attribute_s));
  649.     if (new_attr == NULL) {
  650.         _dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
  651.     return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  652.     }
  653.  
  654.     new_attr->ar_attribute = DW_AT_producer;
  655.     new_attr->ar_attribute_form = DW_FORM_string;
  656.     new_attr->ar_nbytes = strlen(producer_string) + 1;
  657.     new_attr->ar_next = NULL;
  658.  
  659.     new_attr->ar_data = 
  660.     (char *)_dwarf_p_get_alloc(NULL, strlen(producer_string)+1);
  661.     if (new_attr->ar_data == NULL) {
  662.     _dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
  663.     return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  664.     }
  665.  
  666.     strcpy(new_attr->ar_data, producer_string);
  667.     new_attr->ar_rel_type = R_MIPS_NONE;
  668.  
  669.     /* add attribute to the die */
  670.     _dwarf_pro_add_at_to_die(ownerdie,new_attr);
  671.     return new_attr;
  672. }
  673.  
  674.  
  675. Dwarf_P_Attribute
  676. dwarf_add_AT_const_value_signedint (
  677.     Dwarf_P_Die     ownerdie,
  678.     Dwarf_Signed     signed_value,
  679.     Dwarf_Error     *error
  680. )
  681. {
  682.     Dwarf_P_Attribute     new_attr;
  683.     int            leb_size;
  684.  
  685.     if (ownerdie == NULL) {
  686.         _dwarf_p_error(NULL, error, DW_DLE_DIE_NULL);
  687.     return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  688.     }
  689.  
  690.     new_attr = (Dwarf_P_Attribute)
  691.         _dwarf_p_get_alloc(NULL, sizeof(struct Dwarf_P_Attribute_s));
  692.     if (new_attr == NULL) {
  693.         _dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
  694.     return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  695.     }
  696.  
  697.     new_attr->ar_attribute = DW_AT_const_value;
  698.     new_attr->ar_attribute_form = DW_FORM_sdata;
  699.     new_attr->ar_rel_type = R_MIPS_NONE;
  700.     new_attr->ar_next = NULL;
  701.  
  702.     new_attr->ar_data = 
  703.     _dwarf_pro_encode_signed_leb128(signed_value, &leb_size);
  704.     if (new_attr->ar_data == NULL) {
  705.     _dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
  706.     return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  707.     }
  708.     new_attr->ar_nbytes = leb_size;
  709.  
  710.     /* add attribute to the die */
  711.     _dwarf_pro_add_at_to_die(ownerdie,new_attr);
  712.     return new_attr;
  713. }
  714.  
  715.  
  716. Dwarf_P_Attribute 
  717. dwarf_add_AT_const_value_unsignedint (
  718.     Dwarf_P_Die         ownerdie,
  719.     Dwarf_Unsigned     unsigned_value,
  720.     Dwarf_Error     *error
  721. )
  722. {
  723.     Dwarf_P_Attribute     new_attr;
  724.     int            leb_size;
  725.  
  726.     if (ownerdie == NULL) {
  727.         _dwarf_p_error(NULL, error, DW_DLE_DIE_NULL);
  728.     return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  729.     }
  730.  
  731.     new_attr = (Dwarf_P_Attribute)
  732.         _dwarf_p_get_alloc(NULL, sizeof(struct Dwarf_P_Attribute_s));
  733.     if (new_attr == NULL) {
  734.         _dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
  735.     return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  736.     }
  737.  
  738.     new_attr->ar_attribute = DW_AT_const_value;
  739.     new_attr->ar_attribute_form = DW_FORM_udata;
  740.     new_attr->ar_rel_type = R_MIPS_NONE;
  741.     new_attr->ar_next = NULL;
  742.  
  743.     new_attr->ar_data = 
  744.     _dwarf_pro_encode_leb128(unsigned_value, &leb_size);
  745.     if (new_attr->ar_data == NULL) {
  746.     _dwarf_p_error(NULL, error, DW_DLE_ALLOC_FAIL);
  747.     return((Dwarf_P_Attribute)DW_DLV_BADADDR);
  748.     }
  749.     new_attr->ar_nbytes = leb_size;
  750.  
  751.     /* add attribute to the die */
  752.     _dwarf_pro_add_at_to_die(ownerdie,new_attr);
  753.     return new_attr;
  754. }
  755.